def solve(matrix):
    #[i,j] -> [j,n-i-1]
    n=len(matrix)
    for i0 in range(int(n/2)):
        for j0 in range(i0,n-i0-1):
            i,j=i0,j0
            next_value=matrix[i][j]
            for k in range(4):
                this_value=next_value 
                next_value=matrix[j][n-i-1]
                matrix[j][n-i-1]=this_value 
                i,j=j,n-i-1

matrix = [[1,2,3],[4,5,6],[7,8,9]]
solve(matrix)
print(matrix)

matrix = [[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]]
solve(matrix)
print(matrix)



